home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / extw-Xt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-29  |  5.7 KB  |  216 lines

  1. /* Common code between client and shell widgets -- Xt only.
  2.    Copyright (C) 1993, 1994 Sun Microsystems, Inc.
  3.  
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8.  
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free
  16. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  17.  
  18. /* Synched up with: Not in FSF. */
  19.  
  20. /* Written by Ben Wing, September 1993. */
  21.  
  22. #ifdef emacs
  23.  
  24. #include <config.h>
  25.  
  26. #ifndef EXTERNAL_WIDGET
  27. ERROR!  This ought not be getting compiled if EXTERNAL_WIDGET is undefined
  28. #endif
  29.  
  30. void fatal (CONST char *fmt, ...);
  31. #else /* not emacs */
  32. static void fatal (char *msg);
  33. #endif
  34.  
  35. #include <X11/Intrinsic.h>
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include "extw-Xt.h"
  39.  
  40. /* Yeah, that's portable! */
  41. int _XtwaitForSomething(
  42.         Boolean ignoreTimers,
  43.         Boolean ignoreInputs,
  44.         Boolean ignoreEvents,
  45.         Boolean block,
  46.         unsigned long *howlong,
  47.         XtAppContext app
  48.         );
  49.  
  50. #ifdef DEBUG_WIDGET
  51.  
  52. static int geom_masks[] = {
  53.   CWX, CWY, CWWidth, CWHeight, CWBorderWidth, CWSibling, CWStackMode,
  54.   XtCWQueryOnly };
  55. static char *geom_mask_strings[] = {
  56.   "CWX", "CWY", "CWWidth", "CWHeight", "CWBorderWidth",
  57.   "CWSibling", "CWStackMode", "XtCWQueryOnly" };
  58. static int stack_modes[] = {
  59.   Below, TopIf, BottomIf, Opposite, XtSMDontChange };
  60. static char *stack_mode_strings[] = {
  61.   "Below", "TopIf", "BottomIf", "Opposite", "XtSMDontChange" };
  62.  
  63. static void
  64. print_geometry_structure(XtWidgetGeometry *xwg)
  65. {
  66.   int num = sizeof(geom_masks)/sizeof(int);
  67.   int i;
  68.   
  69.   printf ("  masks:");
  70.   for (i=0; i<num; i++)
  71.     if (xwg->request_mode & geom_masks[i])
  72.       printf (" %s", geom_mask_strings[i]);
  73.   printf ("\n");
  74.   printf ("  x:%d y:%d\n", xwg->x, xwg->y);
  75.   printf ("  width:%d height:%d border_width:%d\n", xwg->width,
  76.       xwg->height, xwg->border_width);
  77.   printf ("  sibling: %x\n", xwg->sibling);
  78.   printf ("  stack_mode: ");
  79.   for (i=0, num=sizeof(stack_modes)/sizeof(int); i<num; i++)
  80.     if (xwg->stack_mode == stack_modes[i]) {
  81.       printf ("%s", stack_mode_strings[i]);
  82.       break;
  83.     }
  84.   printf ("\n");
  85. }
  86.  
  87. static void
  88. print_geometry_result (XtGeometryResult res)
  89. {
  90.   printf ("result: %s\n",
  91.       res == XtGeometryYes ? "XtGeometryYes" :
  92.       res == XtGeometryNo ? "XtGeometryNo" :
  93.       res == XtGeometryAlmost ? "XtGeometryAlmost" :
  94.       res == XtGeometryDone ? "XtGeometryDone" :
  95.       "unknown");
  96. }
  97.  
  98. #endif
  99.  
  100. #ifndef emacs
  101.  
  102. static void
  103. fatal (char *msg)
  104. {
  105.   fprintf (stderr, "%s", msg);
  106.   exit (1);
  107. }
  108.  
  109. #endif
  110.  
  111. /* put a geometry specification in the specified property on the window
  112.    of the specified widget, and send a notification message to tell the
  113.    client-side widget about this. */
  114.  
  115. void
  116. extw_send_geometry_value(Display *display, Window win, Atom property,
  117.              en_extw_notify type, XtWidgetGeometry *xwg,
  118.              long data0)
  119. {
  120.   if (xwg != NULL)
  121.     XChangeProperty(display, win, property,
  122.             a_EXTW_WIDGET_GEOMETRY, 32, PropModeReplace,
  123.             (unsigned char *) xwg, sizeof(*xwg)/sizeof(int));
  124.   extw_send_notify_3(display, win, type, data0, 0, 0);
  125. }
  126.  
  127. /* get the geometry specification stored in the specified property of the
  128.    specified widget's window. */
  129.  
  130. void
  131. extw_get_geometry_value(Display *display, Window win, Atom property,
  132.             XtWidgetGeometry *xwg)
  133. {
  134.   Atom dummy;
  135.   int format;
  136.   unsigned long nitems, bytes_after;
  137.   unsigned char *prop;
  138.   
  139.   if (XGetWindowProperty(display, win, property, 0,
  140.              sizeof(*xwg)/4, False, a_EXTW_WIDGET_GEOMETRY,
  141.              &dummy, &format, &nitems, &bytes_after,
  142.              &prop) != Success)
  143.     goto error;
  144.   if (format != 8*sizeof(int) || bytes_after) {
  145.     XFree((char *) prop);
  146.     goto error;
  147.   }
  148.   *xwg = * (XtWidgetGeometry *) prop;
  149.   return;
  150.  
  151.  error:
  152.   fatal("Unable to retrieve property for widget-geometry");
  153. #if 0
  154.   XtAppErrorMsg(XtWidgetToApplicationContext((Widget)w),
  155.         "invalidProperty","get_geometry_value",XtCXtToolkitError,
  156.         "Unable to retrieve property for widget-geometry",
  157.         (String *)NULL, (Cardinal *)NULL);
  158. #endif
  159. }
  160.  
  161. typedef struct {
  162.     Widget w;
  163.     unsigned long request_num;
  164.     en_extw_notify type;
  165. } QueryStruct;
  166.  
  167. /* check if an event is of the sort we're looking for */
  168.  
  169. static Bool
  170. isMine(Display *dpy, XEvent *event, char *arg)
  171. {
  172.     QueryStruct *q = (QueryStruct *) arg;
  173.     Widget w = q->w;
  174.     
  175.     if ( (dpy != XtDisplay(w)) || (event->xany.window != XtWindow(w)) ) {
  176.         return FALSE;
  177.     }
  178.     if (event->xany.serial >= q->request_num) {
  179.       if (event->type == ClientMessage &&
  180.           event->xclient.message_type == a_EXTW_NOTIFY &&
  181.           event->xclient.data.l[0] == 1 - extw_which_side &&
  182.           event->xclient.data.l[1] == q->type)
  183.         return TRUE;
  184.     }
  185.     return FALSE;
  186. }
  187.  
  188. /* wait for a ClientMessage of the specified type from the other widget, or
  189.    time-out.  isMine() determines whether an event matches.  Culled from
  190.    Shell.c. */
  191.  
  192. Bool
  193. extw_wait_for_response(Widget w, XEvent *event, unsigned long request_num,
  194.                en_extw_notify type, unsigned long timeout)
  195. {
  196.     XtAppContext app = XtWidgetToApplicationContext(w);
  197.     QueryStruct q;
  198.  
  199.     XFlush(XtDisplay(w));
  200.     q.w = w;
  201.     q.request_num = request_num;
  202.     q.type = type;
  203.     
  204.     for(;;) {
  205.          /*
  206.           * look for match event
  207.           */
  208.         if (XCheckIfEvent( XtDisplay(w), event, isMine, (char*)&q))
  209.             return TRUE;
  210.         if (_XtwaitForSomething(TRUE, TRUE, FALSE, TRUE, &timeout, app)
  211.         != -1) continue;
  212.         if (timeout == 0)
  213.         return FALSE;
  214.     }
  215. }
  216.